Open
Conversation
Adds a new unit test in ThrowableConsumerTest that calls execute(String, ThrowableConsumer, BiConsumer) with a no-op exception handler to verify the exception-handling path does not propagate an error. Improves coverage for the execute-with-handler scenario.
Codecov Report❌ Patch coverage is
... and 4 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Introduce an abstract test utility LoggingTest that manages Logback logger levels for tests. The class (microsphere-java-core/src/test/java/io/microsphere/LoggingTest.java) uses JUnit 5 annotations to run parameterized (INFO, TRACE) scenarios, with @BeforeEach/@AfterEach methods to set and restore the logger level via a shared LoggerContext. The test is currently @disabled and provides getTargetLogger() to target the package logger.
Import LoggingTest and have ShutdownHookCallbacksThreadTest extend it so the test can leverage shared logging utilities/capture. Also remove an extra trailing blank line.
Update ClassPathResourceConfigurationPropertyLoaderTest to extend LoggingTest and add the corresponding import. This enables logging support/capture for the test class (facilitating inspection of logs during test execution).
Make ArtifactDetectorTest extend LoggingTest to enable logging support in the test. Added import for io.microsphere.LoggingTest and updated the class declaration so tests can leverage the shared logging test utilities.
Wrap the logger.trace call in JarUtils with a logger.isTraceEnabled() check to avoid unnecessary message formatting and exception handling overhead when trace logging is disabled. This change improves performance on the error path when opening a JarFile fails.
Import LoggingTest and have JarUtilsTest extend it so test logging utilities are available. This enables shared logging setup/behavior for the JarUtils tests to improve diagnostics during test runs.
Wrap two logger.trace calls in ClassUtils.java with logger.isTraceEnabled() checks (in class path scanning and in the SimpleJarEntryScanner exception handler). This avoids unnecessary logging overhead/formatting when TRACE is disabled and preserves existing behavior when enabled.
Add import for io.microsphere.LoggingTest and change ClassUtilsTest to extend LoggingTest so the test can leverage shared logging/test utilities. No other test logic was modified.
Wrap trace-level logging calls in FieldUtils with logger.isTraceEnabled() checks to avoid unnecessary string construction when trace logging is disabled. Changes apply to findField and the exception handlers handleIllegalAccessException and handleIllegalArgumentException. No functional change to exception behavior; this is an optimization to reduce logging overhead.
Add io.microsphere.LoggingTest import and update FieldUtilsTest to extend LoggingTest so the test class inherits logging/diagnostic behavior. No other logic changes were made.
Add a logger.isTraceEnabled() check before invoking logger.trace in ManifestArtifactResourceResolver. This avoids unnecessary string formatting and potential expensive artifact representation creation when trace logging is disabled, reducing runtime overhead without changing behavior.
Wrap existing logger.trace(...) calls with logger.isTraceEnabled() checks to avoid unnecessary string formatting when trace logging is disabled. Applied to three locations in StreamArtifactResourceResolver where missing archive, missing JarEntry, or missing artifact metadata file are logged. No behavioral changes beyond logging performance improvement.
Import LoggingTest and make AbstractArtifactResourceResolverTest extend it so the artifact resolver tests can use shared logging utilities and capture test logs consistently.
Replace Loggable abstract class with a Loggable interface that provides default logging methods (logger is now obtained per-call). Update test classes to implement Loggable instead of extending it, adjust class/interface declaration orders where necessary, and add a LoggingTest base class to ExecutorUtilsTest (with import). Also update ModifierTest to avoid referencing the removed protected logger field by checking Proxy.h instead.
Wrap the trace log call in ExecutorUtils.shutdown(...) with a logger.isTraceEnabled() check to avoid unnecessary logging overhead when trace level is disabled. This prevents potential cost from message formatting or parameter evaluation in high-frequency shutdown paths.
Wrap the trace log call in IOUtils with logger.isTraceEnabled() to avoid unnecessary message formatting and argument evaluation when trace level is disabled. This reduces overhead in the stream copy path while preserving the original logging behavior.
Import io.microsphere.LoggingTest and update IOUtilsTest to extend LoggingTest so the test class can reuse shared logging/test utilities (captures logging or common setup/teardown).
Wrap trace logging calls with logger.isTraceEnabled() checks to avoid unnecessary message formatting and potential expensive operations when trace level is disabled. Applied to the file-dispatch log in the event dispatch path and the directory registration log in registerDirectoriesToWatchService.
Import io.microsphere.LoggingTest and update StandardFileWatchServiceTest to extend LoggingTest (while retaining Loggable). This enables reuse of logging test utilities in the test class.
Wrap the logger.trace call in StandardURLStreamHandlerFactory#createURLStreamHandlerFromDefaultFactory with a logger.isTraceEnabled() check to avoid unnecessary logging overhead and follow conditional logging best practices.
Import LoggingTest and have StandardURLStreamHandlerFactoryTest extend it so the test inherits shared logging setup/fixtures. This enables consistent logging behavior for the test class.
Wrap the logger.trace call in URLUtils.java with an if (logger.isTraceEnabled()) check to avoid unnecessary logging message formatting when trace is disabled. Preserves existing behavior (returns null for whitespace in protocol) while reducing runtime overhead during protocol validation.
Add io.microsphere.LoggingTest import and have URLUtilsTest extend LoggingTest so the test can use shared logging/test utilities (enabling log capture/configuration during test execution).
Wrap the trace log call in ClassicProcessIdResolver#current() with logger.isTraceEnabled() to avoid unnecessary message construction when trace logging is disabled. Preserves existing behavior when trace is enabled while reducing potential performance overhead.
Update the test class to extend io.microsphere.LoggingTest and add the required import so the test can use shared logging utilities/capture. No behavior changes to test logic.
Wrap the logger.trace call in ModernProcessIdResolver.current() with logger.isTraceEnabled() to avoid unnecessary logging overhead (message formatting) when TRACE is disabled. This reduces runtime cost for the PID resolution path.
Import io.microsphere.LoggingTest and make ModernProcessIdResolverTest extend LoggingTest. This enables shared logging setup/utility for the test class so test logging can be captured or configured consistently.
Wrap the logger.trace(...) call in ProcessExecutor with a logger.isTraceEnabled() check to avoid unnecessary message formatting when trace logging is disabled. The change sits in the finally block after removing unfinished processes and is a small performance optimization.
Add import for LoggingTest and change ProcessExecutorTest from implementing Loggable to extending LoggingTest (while still implementing Loggable). This lets the test reuse shared logging/test utilities (captures/initialization) when running process-related tests.
Wrap the trace logging call in a logger.isTraceEnabled() check to avoid unnecessary logging overhead when trace level is disabled. This change limits work done for the PID resolution log message in VirtualMachineProcessIdResolver.
Add LoggingTest support to VirtualMachineProcessIdResolverTest by importing io.microsphere.LoggingTest and changing the test class to extend LoggingTest. This enables logging capture/behavior provided by the base test class during the resolver tests.
Introduce addIfAbsent(List<T>, T) utility method that adds an element only if it's not already present in the list. The method returns true when the element was added and false if the list already contained the value (uses contains() then add()). Provides a convenient way to avoid duplicates for list-based collections.
Add a static import and a new unit test (testAddIfAbsent) in ListUtilsTest to verify ListUtils.addIfAbsent behavior: it returns true when adding a new element, false when adding a duplicate, and true when adding another distinct element.
Import ListUtils.addIfAbsent and ArrayUtils.length, replace manual array length checks and explicit contains()-then-add patterns with addIfAbsent for interface and supertype insertion, and use length(...) for array sizing. Also simplify superclass addition and perform minor cleanup (removed trailing newline). Improves readability and centralizes duplicate-check logic.
Add unit tests verifying TypeFinder.getSuperTypes behavior: testGetSuperTypes checks resolution of String's supertypes (Object, Serializable, Comparable) using classGetSuperClassFunction; testGetSuperTypesWithNullType verifies that passing null returns an emptyList for various include flags. Also add required imports and static imports (Serializable, ofList, ofArray, classGetSuperClassFunction) to support the new tests.
Add unit tests for TypeFinder utilities: verify genericTypeGetSuperClassFunction and genericTypeGetInterfacesFunction return null for null input, and test addSuperTypes behavior (no additions when flags are false, and additions when interfaces/superclasses are enabled). Also add necessary static imports and assertions used by the new tests.
Update FieldUtilsTest to use the new FieldUtils.handleFieldException API. Replaced the static import of handleIllegalAccessException with handleFieldException, added assertDoesNotThrow import, renamed the test to testHandleFieldException, and adjusted the invocation to match the new method signature (removed the accessibility argument). This reflects an API change in FieldUtils.
Add a unit test for the JSONArray(JSONTokener) constructor in JSONArrayTest. Adds a static import for assertDoesNotThrow and a test method that asserts a JSONTokener with '[1,2,3]' does not throw, while a JSONTokener with '{}' results in a JSONException.
In SimpleFileScanner, replace `this.scan(subFile, recursive, ioFileFilter)` with `scan(subFile, recursive, ioFileFilter)` to remove an unnecessary qualifier. This is a minor stylistic cleanup with no functional change.
Add two unit tests to SimpleFileScannerTest: one verifies scanning an empty temporary directory returns that directory, and the other verifies scanning a temporary file returns that file. Also add imports for helper methods (createRandomTempDirectory/createRandomTempFile), IOException, and assertTrue.
Introduce JDK9+ StackWalker support and MethodHandle usage for sun.reflect.Reflection#getCallerClass. This change: - Adds optional STACK_WALKER and STACK_WALKER_STACK_FRAME class resolution and initializes a StackWalker instance for efficient frame inspection. - Replaces direct reflective invocation of sun.reflect.Reflection#getCallerClass with a MethodHandle (findPublicStatic) and prefers it when available. - Adds new helper paths to obtain caller class names: prefer sun.reflect Reflection, then StackWalker, then fall back to stack trace. - Refactors and consolidates multiple getCallerClass/getCallerClassName implementations and related invocation-frame calculations. - Updates imports to use MethodHandle, Streams, and MethodUtils helpers and removes some older reflection usages. These changes improve compatibility with newer JDKs (noisy reflective access / InaccessibleObjectException) and provide a more robust, layered strategy for determining caller classes.
Refactor and expand ReflectionUtilsTest to exercise new caller-resolution strategies (StackTrace/StackWalker and sun.reflect reflection). Introduces CALLER_CLASS/CALLER_CLASS_NAME constants, replaces older GeneralJVM/SunJVM assertions with StackTrace/StackWalker variants, and adds tests for frame bounds, StackWalker behavior across Java versions (using VersionUtils), and expected exceptions on unsupported JVMs. Also adjusts imports and uses assertThrows where appropriate.
Update ReflectionUtilsBenchmark: add static imports for new helpers, rename benchmark methods to reflect StackWalker/StackTrace strategies, and add a benchmark that invokes the sun.reflect.Reflection-based lookup (commented out). These changes clarify which caller lookup approach is being measured and prepare the test for additional comparisons.
Call getCallerClassName with a fixed index (1) instead of using invocationFrame + 1 to avoid out-of-range/throwing behavior for large frame values. Update the test to expect no exception when passing an excessively large frame (use assertDoesNotThrow) and add the necessary import.
Raise the StackWalker limit from 5 to 9 in getCallerClassNamesInStackWalker to collect more frames. Replace the previous hardcoded caller offset (1) with a computed offset (invocationFrame + 2) when resolving the caller class, ensuring correct caller resolution for deeper or nested invocation stacks.
Remove StackWalker-based caller lookup and related reflection/version utilities from StackTraceUtils. This change deletes imports, constants, static initializers, logger, and methods such as getCallerClassName, getCallerClassNames, getCallerClassNameInGeneralJVM and other StackWalker/StackFrame helpers, leaving only getStackTrace() and the private constructor. The class is simplified to no longer perform stack-walking or reflectively invoke StackWalker APIs.
Replace multiple caller-name and Java-version-dependent tests with a single simple test that asserts StackTraceUtils.getStackTrace() is not null. Clean up imports accordingly and remove tests for getCallerClassName, getCallerClassNames and VersionUtils checks.
Delete the JMH benchmark class StackTraceElementUtilsBenchmark from microsphere-java-core tests. Removes io/microsphere/util/StackTraceElementUtilsBenchmark.java which contained benchmarks for StackTraceUtils (getCallerClassName and getCallerClassNameInGeneralJVM).
Introduce utilities to determine caller classes/names using Thread#getStackTrace. A static invocationFrameOffset is computed at class init by scanning StackTraceElement frames for this utility class, and helper methods were added: getCallerClassInStatckTrace(), getCallerClassNameInStackTrace(), getCallerClassInStatckTrace(int) and getCallerClassNameInStackTrace(int). The implementation resolves class names to Class<?> via resolveClass and returns null when a target frame is unavailable.
Add unit tests to StackTraceUtilsTest covering caller-related utilities. Introduces CALLER_CLASS and CALLER_CLASS_NAME constants and tests for getCallerClassInStatckTrace(), getCallerClassNameInStackTrace(), and an out-of-range frame case (assertNull). Also adds necessary static imports for the new assertions and methods.
Rename and consolidate stack-frame offset fields and simplify caller-class detection logic. Fields like sunReflectReflectionInvocationFrame and stackWalkerInvocationFrame were renamed to sunReflectReflectionInvocationFrameOffset and stackWalkerInvocationFrameOffset, and offset calculations were adjusted to account for invocation-level increments. Removed several stack-trace-based helper methods and fallbacks, simplified getCallerClassInSunReflectReflection to always try the MethodHandle call, and updated StackWalker-related logic to use the new offsets. Tests were updated to import StackTraceUtils helpers and to reflect the new offset behavior and assertions. This change reduces reliance on fragile stack-trace indexing and unifies offset handling across JVM detection paths.
Replace the fully-qualified ReflectionUtils.getCallerClassNameInStackTrace() call with a static import of getCallerClassNameInStackTrace from StackTraceUtils in ReflectionUtilsBenchmark. This clarifies the method origin and keeps the test import style consistent with other helper methods.
Replace reflection-based getCallerClass(...) with StackTraceUtils.getCallerClassInStatckTrace(...) and update import accordingly. Adjust the default caller frame in getCallerClassLoader() from 4 to 5 to account for the different stack depth used by the new stack-trace-based lookup.
Change the stack depth used to resolve the caller ClassLoader from 4 to 5 when loadedClass is null. This adjusts the caller lookup to account for an additional stack frame in the call chain so the correct ClassLoader is returned, preventing incorrect loader resolution in certain call contexts.
Introduce SecurityUtils utility to manage the java.security.policy system property (constant, getter, and setters accepting String and File). Adds annotations and a private constructor. Include JUnit 5 tests (SecurityUtilsTest) that verify the constant and set/get behavior, prepare a module base path for resources, and clear system properties after each test.
Add class-load-test.policy under microsphere-java-core/src/test/resources/META-INF that grants java.security.AllPermission for test runs. This enables unrestricted class loading and security permissions during class-load related tests.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This pull request adds an additional test case to improve coverage of exception handling in the
ThrowableConsumerTestclass.Testing improvements:
testExecute3OnHandleExceptiontest method toThrowableConsumerTest.javato verify the behavior of theexecutemethod when handling exceptions.